/**
  项目类别管理
*/
<template>
    <div>
        <el-card shadow="never" v-loading="loading" body-style="padding: 24px;" class="card-margin">
            <h1 class="condition-title">{{$t('projectCategory.projectCategory')}}</h1>
            <div class="float-left associated-conditional-input">
                <KeywordInput
                    v-model="queryForm.condition.name"
                    :placeholder="$t('projectCategory.pleaseEnterItem')"
                    @enter="onSubmit"
                />
            </div>
            <div class="edu-opertion-bar sub-title">
                <div class="float-right" style="display: flex;">
                    <el-button type="primary" @click="exportAdd">{{$t('projectCategory.add')}}</el-button>
                </div>
            </div>
            <edu-table
                :pagination="false"
                :tooltipEffect="tooltipEffect"
                stripe
                :data="dataList"
                size="mini"
                @selection-change="handleSelectionChange"
            >
                <edu-table-column :label="$t('projectCategory.projectNumber')" prop="typeCode"></edu-table-column>
                <edu-table-column :label="$t('projectCategory.projectName')" prop="typeName"></edu-table-column>
                <edu-table-column :label="$t('projectCategory.remark')" prop="remark"></edu-table-column>
                <edu-table-column :label="$t('projectCategory.operate')" fit width="150">
                    <template slot-scope="props">
                        <el-button
                            type="text"
                            @click="editOutline(props.row)"
                        >{{$t('graduate.edit')}}</el-button>
                        <el-button
                            v-if="props.row.defaultFlag =='0'"
                            type="text"
                            @click="deleteRoster(props.row)"
                        >{{$t('common.btn.delete')}}</el-button>
                    </template>
                </edu-table-column>
            </edu-table>
            <el-row type="flex" class="row-bg" justify="end">
                <el-col>
                    <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="queryForm.pageNum_"
                        :page-sizes="[20, 40, 80, 100]"
                        :page-size="queryForm.pageSize_"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="queryForm.total_"
                        style="float:right;margin-top:10px"
                    ></el-pagination>
                </el-col>
            </el-row>
        </el-card>
        <el-dialog
            @close="dataObjit={}"
            :before-close="beforeClose"
            :title="titleList"
            width="40%"
            :visible.sync="addflag"
            :show-close="beforeClose"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
        >
            <projectCategoryAdd
                ref="addform"
                @cancel-dialog="changeClose"
                :dataQueryForm="dataQueryForm"
                :showFlag="addflag"
                :dataProp="dataProp"
                :dataList="mainbase"
                :dataListProp="dataObjit"
                @close="(flag) => { addflag = flag }"
                @affirm-form="addrmForm"
            ></projectCategoryAdd>
        </el-dialog>
        <edu-export-dialog
            :disabled="exportButton"
            :title="$t('message.prompt')"
            ref="downloadRef"
            :data="exportResult"
        ></edu-export-dialog>
    </div>
</template>
<script>
import { queryDic } from 'common/src/api/dictionary'
import UTILS from 'common/src/utils/utils'
import projectCategoryAdd from 'common/src/views/switchAndResourceManagement/component/projectCategoryAdd'
import graduateStudent from 'common/src/api/graduateStudent/graduateStudent'
import graduateStudentApi from 'common/src/api/graduateStudent/graduateStudent'
import interAcaConference from 'common/src/api/internationalCommunication/interAcaConference'

export default {
    components: {
        projectCategoryAdd
    },
    data() {
        return {
            indexKey: '1', // 面包屑
            title: '',
            titleList: '',
            fileList: [],
            category: { category: 1 },
            mainbase: '专家',
            showDate: true,
            addflag: false,
            tableFlag: false,
            dataQueryForm: {},
            copyDialog: false,
            exportButton: false,
            exportResult: null,
            checkTopicListForm: {
                dataList: []
            },
            multipleSelection: [],
            queryForm: {
                pageNum_: 1,
                pageSize_: 20,
                condition: {
                    name: ''
                }
            },
            dataListProp: {},
            dataProp: '',
            copyTime: {
                time: ''
            },
            options: {
                facultys: [],
                timeList: [],
                title: []
            },
            defaultFlag: '',
            id: '',
            formsLearn: [],
            dataList: [],
            breadPath: {
                label: this.$t('graduate.graduate'),
                key: '1',
                children: [
                    {
                        key: '2',
                        label: ''
                    }
                ]
            }
        }
    },
    created() {
        this.postApproveAgree(this.queryForm)
    },
    mounted() {
        this.getOptions()
    },
    methods: {
        postApproveAgree(date) {
            interAcaConference.projectTypes(date).then(res => {
                this.queryForm.pageNum_ = res.data.pageNum_
                this.queryForm.pageSize_ = res.data.pageSize_
                this.queryForm.total_ = res.data.total_
                this.dataList = res.data.list
            })
        },
        getOptions() {
            // 筛选条件字典查询
            let data = {
                lang: this.$store.getters.language || 'cn',
                type: 'allChild',
                keys: ['profession']
            }
            queryDic(data).then(res => {
                UTILS.fillSelect(
                    {
                        title: 'profession'
                    },
                    res.data,
                    this.options
                )
            })
        },

        // 编辑
        exportEdit() {
            this.showDate = false
        },
        // 搜索/筛选
        onSubmit() {
            this.queryForm.pageNum_ = 1
            this.postApproveAgree(this.queryForm)
        },
        // 新增
        exportAdd() {
            this.title = this.$t('graduate.add')
            this.dataProp = '新增'
            this.titleList = this.$t('graduate.add')
            this.dataQueryForm = this.queryForm
            this.addflag = true
        },
        // 取消
        changeClose(param) {
            this.addflag = param
        },
        // 取消
        beforeClose(param) {
            this.$refs.addform.cancelDialog()
        },
        tableClose() {
            this.tableFlag = false
        },
        // 新增保存（编辑保存）
        addrmForm(param, data) {
            if (this.dataProp === '编辑') {
                interAcaConference.projectTypesEidt(param).then(res => {
                    this.$message.success(this.$t('internship.successfully'))
                    this.addflag = false
                    this.postApproveAgree(data)
                    this.$refs.addform.confirmInner()
                })
            } else if (this.dataProp === '新增') {
                let params = {
                    typeName:param.typeName,
                    remark: param.remark
                }
                interAcaConference.projectTypesAdd(params).then(res => {
                    this.$message.success(this.$t('internship.successfully'))
                    this.addflag = false
                    this.postApproveAgree(data)
                    this.$refs.addform.confirmInner()
                })
            }
        },
        handleSelectionChange(val) {
            this.multipleSelection = val
        },

        // 编辑
        editOutline(row) {
            let params = {
                id: row.id
            }
            interAcaConference.projectTypesDetail(params).then(res => {
                this.dataProp = '编辑'
                this.titleList = this.$t('graduate.edit')
                this.dataObjit = res.data
                this.dataQueryForm = this.queryForm
                this.addflag = true
            })
        },
        // 删除
        deleteRoster(row) {
            this.$delConfirm(this.$t('您确定要删除吗？')).then(_ => {
                this.deleteBaseAssessSettingRow(row.id)
            })
        },
        deleteBaseAssessSettingRow(id) {
            interAcaConference
                .projectTypesDelete({
                    id: id
                })
                .then(res => {
                    if (res.code === 200) {
                        this.$message.success(this.$t('common.tips.deleteSuccess'))
                        this.onSubmit()
                    }
                })
        },

        // 详情
        detailsOutline(row) {
            this.dataObjit = row
            this.mainbase = '专家'
            this.tableFlag = true
        },
        // 关闭弹框
        changeProp() {
            this.addflag = false
        },
        // 查看考核指标表
        indicatorsList() {},
        // 重置
        reset() {
            for (let key in this.queryForm.condition) {
                if (key !== 'category') {
                    this.queryForm.condition[key] = ''
                }
            }
            this.queryForm.pageNum_ = 1
            this.postApproveAgree(this.queryForm)
        },

        handleSizeChange(val) {
            this.queryForm.pageSize_ = val
            this.queryForm.pageNum_ = 1
            this.postApproveAgree(this.queryForm)
        },
        handleCurrentChange(val) {
            this.queryForm.pageNum_ = val
            this.postApproveAgree(this.queryForm)
        }
    }
}
</script>
<style lang="scss" scoped>
.condition-title {
    color: #2b3b4e;
    font-size: 18px;
    line-height: 24px;
    font-weight: bold;
}
.edu-page-title {
    span {
        line-height: 24px;
        display: inline-block;
        padding-right: 10px;
        font-size: 18px;
        font-weight: bold;
        color: #2b3b4e;
    }
}
.sub-title {
    margin: 16px 0;
    font-size: 16px;
    color: #000020;
    letter-spacing: 0;
}
.form-item {
    width: 312px;
    height: 32px;
    float: left;
    margin: 0px 10px;
}
.is-enabled-container ::v-deep {
    .el-button {
        cursor: auto;
    }
    .el-button--danger {
        padding: 9px 15px;
        min-width: 0;
    }
}
.inputBox {
    width: 240px !important;
    height: 32px !important;
}
.atooltip {
    background: beige;
    border: black;
}
</style>
